<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>个人中心 - 电影天堂</title>
    <link href="/css/style.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
    <script src="/js/jquery-3.7.1.min.js"></script>
    <style>
        /* 个人中心专属样式 */
        .profile-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .profile-header {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 30px;
            margin-bottom: 30px;
            display: flex;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .profile-avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            object-fit: cover;
            margin-right: 30px;
            border: 3px solid #e9ecef;
        }

        .profile-info h2 {
            margin: 0 0 10px 0;
            color: #333;
        }

        .profile-meta {
            display: flex;
            gap: 20px;
            color: #666;
        }

        .profile-meta span {
            display: flex;
            align-items: center;
        }

        .profile-meta i {
            margin-right: 5px;
            color: #4e73df;
        }

        .profile-tabs {
            display: flex;
            border-bottom: 1px solid #e9ecef;
            margin-bottom: 30px;
        }

        .profile-tab {
            padding: 15px 25px;
            cursor: pointer;
            color: #666;
            font-weight: 500;
            transition: all 0.3s;
            border-bottom: 3px solid transparent;
        }

        .profile-tab:hover {
            color: #4e73df;
        }

        .profile-tab.active {
            color: #4e73df;
            border-bottom-color: #4e73df;
        }

        .profile-tab-content {
            display: none;
        }

        .profile-content {
            background-color: #fff;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .profile-section {
            margin-bottom: 30px;
        }

        .profile-section h3 {
            color: #333;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #e9ecef;
        }

        .profile-form-group {
            margin-bottom: 20px;
        }

        .profile-form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #555;
        }

        .profile-form-group input,
        .profile-form-group textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            transition: border 0.3s;
        }

        .profile-form-group input:focus,
        .profile-form-group textarea:focus {
            border-color: #4e73df;
            outline: none;
        }

        .profile-form-group textarea {
            min-height: 120px;
            resize: vertical;
        }

        .profile-actions {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }

        .btn-save {
            background-color: #4e73df;
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 4px;
            cursor: pointer;
            font-weight: 500;
            transition: background-color 0.3s;
        }

        .btn-save:hover {
            background-color: #3a5bc7;
        }

        .btn-cancel {
            background-color: #f8f9fa;
            color: #666;
            border: 1px solid #ddd;
            padding: 12px 25px;
            border-radius: 4px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s;
        }

        .btn-cancel:hover {
            background-color: #e9ecef;
            color: #333;
        }

        /* 收藏列表样式 */
        .favorites-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 20px;
        }

        .favorite-item {
            position: relative;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s;
        }

        .favorite-item a{
            color: var(--primary-color);
            text-decoration: none;
        }

        .favorite-item:hover {
            transform: translateY(-5px);
        }

        .favorite-item img {
            width: 100%;
            height: 280px;
            object-fit: cover;
        }

        .favorite-item .remove-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            background-color: rgba(255, 0, 0, 0.7);
            color: white;
            border: none;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            opacity: 0;
            transition: opacity 0.3s;
        }

        .favorite-item:hover .remove-btn {
            opacity: 1;
        }

        .favorite-item h4 {
            margin: 10px;
            font-size: 16px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        /* 观看历史样式 */
        .watch-history-list {
            width: 100%;
            border-collapse: collapse;
        }

        .watch-history-list th,
        .watch-history-list td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #e9ecef;
        }

        .watch-history-list th {
            background-color: #f8f9fa;
            color: #666;
            font-weight: 500;
        }

        .watch-history-list tr:hover {
            background-color: #f8f9fa;
        }

        .history-movie-title {
            display: flex;
            align-items: center;
        }

        .history-movie-title img {
            width: 50px;
            height: 70px;
            object-fit: cover;
            margin-right: 15px;
            border-radius: 4px;
        }

        .history-progress {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .progress-bar {
            flex-grow: 1;
            height: 8px;
            background-color: #e9ecef;
            border-radius: 4px;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background-color: #4e73df;
            border-radius: 4px;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .profile-header {
                flex-direction: column;
                text-align: center;
                padding: 20px;
            }

            .profile-avatar {
                margin-right: 0;
                margin-bottom: 20px;
            }

            .profile-meta {
                flex-direction: column;
                align-items: center;
            }

            .profile-tabs {
                flex-wrap: wrap;
            }

            .profile-tab {
                padding: 10px 15px;
            }
        }
    </style>
</head>
<body>
<!-- 头部区域 -->
<header th:replace="~{top}"></header>

<!-- 主要内容区域 -->
<main>
    <div class="profile-container">
        <!-- 个人资料头部 -->
        <div class="profile-header">
            <img alt="用户头像" class="profile-avatar" src="/images/default-avatar.jpg">
            <div class="profile-info">
                <h2 th:text="${session.user.username}">用户名</h2>
                <div class="profile-meta">
                    <span th:text="${session.user.vipDuration > 0 ? 'VIP会员':'普通会员'}"><i class="fas fa-star"></i> VIP会员</span>
                    <span><i class="fas fa-history"></i> 加入于:
                        <span th:text="${#dates.format(session.user.createdAt, 'yyyy-MM-dd')}">2023-01-01</span></span>
                </div>
            </div>
        </div>

        <!-- 选项卡导航 -->
        <div class="profile-tabs">
            <div class="profile-tab active" data-tab="profile" onclick="tabChange(0)">个人资料</div>
            <div class="profile-tab" data-tab="favorites" onclick="getFavoriteMovies()">我的收藏</div>
            <div class="profile-tab" data-tab="history" onclick="tabChange(2)">观看历史</div>
            <div class="profile-tab" data-tab="settings" onclick="tabChange(3)">账号设置</div>
        </div>

        <!-- 选项卡内容 -->
        <div class="profile-content">
            <!-- 个人资料选项卡 -->
            <div class="profile-tab-content" id="profile" style="display: block">
                <div class="profile-section">
                    <h3>基本信息</h3>
                    <form>
                        <div class="profile-form-group">
                            <label for="username">用户名</label>
                            <input disabled id="username" th:value="${session.user.username}" type="text"
                                   value="用户名">
                        </div>
                        <div class="profile-form-group">
                            <label for="email">电子邮箱</label>
                            <input disabled id="email" th:value="${session.user.email}" type="email"
                                   value="user@example.com">
                        </div>
                        <div class="profile-form-group">
                            <label for="nickname">昵称</label>
                            <input id="nickname" th:value="${session.user.username}" type="text" value="电影爱好者">
                        </div>
                        <div class="profile-form-group">
                            <label for="bio">个人简介</label>
                            <textarea id="bio">热爱电影，每周至少看三部电影！</textarea>
                        </div>
                        <div class="profile-actions">
                            <button class="btn-save" type="button">保存修改</button>
                            <button class="btn-cancel" type="button">取消</button>
                        </div>
                    </form>
                </div>
            </div>


            <!--             我的收藏选项卡 -->
            <div class="profile-tab-content" id="favorites">
                <div class="profile-section">
                    <h3>我的电影收藏</h3>
                    <div class="favorites-list" id="favorites-list">
                        <!-- 收藏的电影项 -->


                        <!-- 空状态 -->
                        <div class="empty-state" th:if="${#lists.isEmpty(favorites)}">
                            <i class="fas fa-heart-broken"
                               style="font-size: 50px; color: #ddd; margin-bottom: 20px;"></i>
                            <h3>您还没有收藏任何电影</h3>
                            <p>浏览电影时点击"收藏"按钮来收藏您喜欢的电影</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 观看历史选项卡 -->
            <div class="profile-tab-content" id="history">
                <div class="profile-section">
                    <h3>最近观看</h3>
                    <table class="watch-history-list" th:if="${not #lists.isEmpty(watchHistory)}">
                        <thead>
                        <tr>
                            <th>电影名称</th>
                            <th>观看时间</th>
                            <th>观看进度</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>
                                <a class="history-movie-title">
                                    <img alt="电影海报" src="">
                                    <span>电影标题</span>
                                </a>
                            </td>
                            <td>2023-05-15 14:30</td>
                            <td>
                                <div class="history-progress">
                                    <span>50%</span>
                                    <div class="progress-bar">
                                        <div class="progress-fill"></div>
                                    </div>
                                </div>
                            </td>
                            <td>
                                <button class="btn-continue">继续观看</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>

                    <!-- 空状态 -->
                    <div class="empty-state">
                        <i class="fas fa-history" style="font-size: 50px; color: #ddd; margin-bottom: 20px;"></i>
                        <h3>您还没有观看历史</h3>
                        <p>观看电影后会自动记录您的观看进度</p>
                    </div>
                </div>
            </div>

            <!--             账号设置选项卡 -->
            <div class="profile-tab-content" id="settings">
                <div class="profile-section">
                    <h3>账号安全</h3>
                    <form>
                        <div class="profile-form-group">
                            <label for="current-password">当前密码</label>
                            <input id="current-password" placeholder="输入当前密码" type="password">
                        </div>
                        <div class="profile-form-group">
                            <label for="new-password">新密码</label>
                            <input id="new-password" placeholder="输入新密码" type="password">
                        </div>
                        <div class="profile-form-group">
                            <label for="confirm-password">确认新密码</label>
                            <input id="confirm-password" placeholder="再次输入新密码" type="password">
                        </div>
                        <div class="profile-actions">
                            <button class="btn-save" type="button">修改密码</button>
                        </div>
                    </form>
                </div>

                <div class="profile-section">
                    <h3>隐私设置</h3>
                    <form>
                        <div class="profile-form-group">
                            <label class="switch">
                                <input checked type="checkbox">
                                <span class="slider round"></span>
                            </label>
                            <span style="margin-left: 10px;">允许他人查看我的收藏</span>
                        </div>
                        <div class="profile-form-group">
                            <label class="switch">
                                <input type="checkbox">
                                <span class="slider round"></span>
                            </label>
                            <span style="margin-left: 10px;">允许他人查看我的观看历史</span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</main>

<!-- 页脚区域 -->
<footer th:replace="~{footer :: footer}"></footer>

<!-- 站点 JavaScript -->
<script src="/js/main.js" th:src="@{/js/main.js}"></script>
<script>
    function tabChange(index) {
        let tab = document.getElementsByClassName('profile-tab-content');
        for (let i = 0; i < tab.length; i++) {
            tab[i].style.display = 'none';
        }
        tab[index].style.display = 'block';
    }

    function getFavoriteMovies() {
        tabChange(1);
        const favoritesList = document.getElementById('favorites-list');
        $.get("/movie/favorite", function (data) {
            console.log(data)
            favoritesList.innerHTML = data.map(movie => `
                                    <div class="favorite-item">
                                        <a href="/movie/detail?id=${movie.id}">
                                            <img src="/image/${movie.coverUrl}" alt="电影海报">
                                            <h4>${movie.title}</h4>
                                        </a>
                                        <button class="remove-btn" title="移除收藏">
                                            <i class="fas fa-times"></i>
                                        </button>
                                    </div>
    `).join('');
        });



    }


    $(document).ready(function () {
        // 选项卡切换功能
        $('.profile-tab').click(function () {
            // 移除所有active类
            $('.profile-tab').removeClass('active');

            // 添加active类到当前选项卡
            $(this).addClass('active');

        });

        // 收藏电影删除功能
        $('.remove-btn').click(function (e) {
            e.stopPropagation();
            if (confirm('确定要从收藏中移除这部电影吗？')) {
                $(this).parent().fadeOut(300, function () {
                    $(this).remove();
                    // 这里可以添加AJAX请求来更新服务器端的收藏数据
                    const favoritesCount = $('.favorite-item').length;
                    $('#favorites h3 span').text(favoritesCount);

                    if (favoritesCount === 0) {
                        $('.favorites-list').html(`
                            <div class="empty-state">
                                <i class="fas fa-heart-broken" style="font-size: 50px; color: #ddd; margin-bottom: 20px;"></i>
                                <h3>您还没有收藏任何电影</h3>
                                <p>浏览电影时点击"收藏"按钮来收藏您喜欢的电影</p>
                            </div>
                        `);
                    }
                });
            }
        });

        // 表单提交处理
        $('.btn-save').click(function () {
            // 这里可以添加表单验证和AJAX提交
            alert('个人信息已保存！');
        });
    });
</script>
</body>
</html>